﻿@model USERS.CYT369.COM.Models.AccountView.LoginViewModel
@{
    ViewBag.Title = "用户登录";
    ViewBag.HeaderName = "欢迎登录";
    Layout = "_RegisterLoginLayout1";
}

@section scripts{
    <script type="text/javascript">
        function RefreshCaptchaCode(img) {
            $(img).attr("src", "@Url.Content("~/Account/GetCaptcha")?p=" + new Date().getTime());
        }
        function OnTextKeyDown(e) {
            if (event.keyCode == 13) {
                DoLogin();
            }
        }

        function DoLogin() {
            var user = {
                UserName: $("#UserName").val().trim(),
                Password: $("#Password").val().trim(),
                CaptchaCode: $("#CaptchaCode").val().trim(),
                ReturnUrl: $("#ReturnUrl").val().trim(),
                ResultUrl: $("#ResultUrl").val().trim(),
                AppID: $("#AppID").val().trim(),
                RememberMe: $("#remeberMeChk")[0].checked,
            };
            if (user.UserName.length < 1) {
                $("#error_msg").text("登录用户名不能为空!");
                $(".err-msg").show();
                return;
            }
            if (user.Password.length < 1) {
                $("#error_msg").text("密码不能为空!");
                $(".err-msg").show();
                return;
            }

            if (user.CaptchaCode < 1) {
                $("#error_msg").text("验证码不能为空!");
                $(".err-msg").show();
                return;
            }

            $("#submit").attr('disabled', 'disabled');
            $("#submit").addClass("submit-btn-disable");

            $.ajax({
                url: '@Url.Content("~/Account/Login")',
                type: "POST",
                dataType: "JSON",
                contentType: "application/json;charset=utf-8",
                data: JSON.stringify(user),
                success: function (e, s, xhr) {
                    if (e.Result) {
                        var s = xhr.getResponseHeader("Set-Cookie");
                        location.href = e.Msg;
                    } else {
                        $("#error_msg").text(e.Msg);
                        $(".err-msg").show();

                        $("#submit").removeAttr('disabled');
                        $("#submit").removeClass("submit-btn-disable");
                    }
                },
                error: function () {
                    $("#submit").removeAttr('disabled');
                    $("#submit").removeClass("submit-btn-disable");
                }
            });
        }
    </script>
}

<div class="page-bg" style="position:relative">
    <img class="bg" src="~/css/images/login-bg.jpg" />
    <div class="form-panel">
        <div class="panel-name">用户登录</div>
        <div class="err-msg"><i class="fa fa-info-circle"></i><span id="error_msg"></span></div>
        <form class="form" method="post" action="~/Account/Login" autocomplete="off">
            <div class="row">
                <input class="input iphone-input" id="UserName" name="UserName" type="text" placeholder="手机号" maxlength="11" autocomplete="off" style="width:220px" />
                <div class="input-icon icon-username"></div>
            </div>
            <div class="row">
                <input class="input" id="Password" name="Password" type="password" placeholder="密码" autocomplete="off" maxlength="16" style="width:220px" />
                <div class="input-icon icon-password"></div>
            </div>
            <div class="row">
                <input class="input" id="CaptchaCode" name="CaptchaCode" type="text" placeholder="输入6位验证码" autocomplete="off" maxlength="6" style="width:125px" onkeypress="OnTextKeyDown(this)" />
                <div class="input-icon icon-captcha"></div>
                <img class="captcha-img" src="~/Account/GetCaptcha" onclick="RefreshCaptchaCode(this)" />
            </div>
            <div class="row" style="margin-top:10px;">
                <div class="remember-info">
                    <span><input id="remeberMeChk" type="checkbox" value="1" /><label for="remeberMeChk">两周内自动登录</label></span>
                    <span>
                        <a href="~/Account/ForgotPassword">忘记密码</a>
                    </span>
                </div>
                <input name="ReturnUrl" id="ReturnUrl" type="hidden" value="@ViewBag.ReturnUrl" />
                <input name="ResultUrl" id="ResultUrl" type="hidden" value="@ViewBag.ResultUrl" />
                <input name="AppID" id="AppID" type="hidden" value="@ViewBag.AppID" />
                <input name="submit" id="submit" class="submit-btn" type="button" onclick="DoLogin()" value="登 录" />
            </div>
        </form>
        <div class="panel-expand">
            <div class="link-area">
                <span>没有账号？</span>
                <a class="a" href="~/Account/Register?appid=@ViewBag.AppID&returnUrl=@ViewBag.ReturnUrl&resultUrl=@ViewBag.ResultUrl">立即注册新账号&nbsp;&gt;&gt;</a>
            </div>
        </div>
    </div>

</div>
